/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div
      id="explanation"
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" alt />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul>
          <li>如果分销开关关闭，那么不会平台启用分销模块，每个商品独立设置分销金</li>
          <li>如果规则由平台设置，那么分销规则统一按平台设置的规则返利，否则按各商家自行设置的比例规则</li>
          <li>所有分销商获佣比例之和不超过100%，比例为0则也视为不参与分佣，平台分销规则可针对分销商设置等级</li>
        </ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>
    <el-form ref="form" :model="form" label-width="200px" label-position="right">
      <el-form-item label="分销开关">
        <el-switch v-model="form.switch" active-value="1" inactive-value="0"></el-switch>
        <p class="notic">分销开关</p>
      </el-form-item>
      <el-form-item label="分销规则设置">
        <el-radio-group v-model="form.distribut_set_by">
          <el-radio label="0">由平台设置</el-radio>
          <el-radio label="1">由商家设置</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="推荐开店有效期">
        <el-select v-model="form.open_store_time" placeholder="请选择推荐开店有效期" size="mini">
          <el-option label="1天" value="1"></el-option>
          <el-option label="2天" value="2"></el-option>
          <el-option label="3天" value="3"></el-option>
          <el-option label="4天" value="4"></el-option>
          <el-option label="5天" value="5"></el-option>
          <el-option label="6天" value="6"></el-option>
          <el-option label="7天" value="7"></el-option>
          <el-option label="8天" value="8"></el-option>
          <el-option label="9天" value="9"></el-option>
          <el-option label="10天" value="10"></el-option>
          <el-option label="长期" value="0"></el-option>
        </el-select>
        <p class="notic">例：多少天内开店成功，才能算是这个人推荐的的店</p>
      </el-form-item>
      <el-form-item label="返佣级数">
        <el-select v-model="form.regrade" placeholder="请选择返佣级数" size="mini">
          <el-option label="返一级" value="0"></el-option>
          <el-option label="返二级" value="1"></el-option>
          <el-option label="返三级" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="一级分销商获佣百分比">
        <el-input v-model="form.first_rate" size="mini"></el-input>
        <p class="notic">购买者直接推荐人返佣占商品分销金比例</p>
      </el-form-item>
      <el-form-item label="二级分销商获佣百分比">
        <el-input v-model="form.second_rate" size="mini"></el-input>
        <p class="notic">购买者推荐人的上级返佣占商品分销金比例</p>
      </el-form-item>
      <el-form-item label="三级分销商获佣百分比" size="mini">
        <el-input v-model="form.third_rate"></el-input>
        <p class="notic">购买者推荐人的上上级占商品分销金比例</p>
      </el-form-item>
      <el-form-item label="二维码相关设定"></el-form-item>
      <el-form-item label="页面二维码背景">
        <el-upload
          class="avatar-uploader"
          :action="apiHead + '/mall/upload?type=weixin'"
          :show-file-list="false"
          :on-success="handleQRBack"
          :before-upload="beforeAvatarUpload"
        >
          <el-image
            v-if="form.qr_back"
            :src="form.qr_back"
            style="width:90px; height:90px; display:block;"
          ></el-image>
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </el-form-item>
      <el-form-item label="‘我的二维码’大背景">
        <el-upload
          class="avatar-uploader"
          :action="apiHead + '/mall/upload?type=weixin'"
          :show-file-list="false"
          :on-success="handleQRBigBack"
          :before-upload="beforeAvatarUpload"
        >
          <el-image
            v-if="form.qr_big_back"
            :src="form.qr_big_back"
            style="width:90px; height:90px; display:block;"
          ></el-image>
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </el-form-item>
      <el-form-item label="微信菜单关键字">
        <el-input v-model="form.qrcode_menu_word" size="mini"></el-input>
        <p class="notic">用户点击微信菜单中的某项，响应‘我的二维码’图片</p>
      </el-form-item>
      <el-form-item label="微信输入关键字">
        <el-input v-model="form.qrcode_input_word" size="mini"></el-input>
        <p class="notic">用户在微信中输入的文本，响应‘我的二维码’图片</p>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit" :loading="subLoading">确认提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getConfigs, updateConfigs } from "@/utils/api";
export default {
  data() {
    return {
      form: {},
      subLoading: false
    };
  },
  components: {},
  created() {
    this.getConfigs();
  },
  methods: {
    getConfigs() {
      var that = this;
      getConfigs({
        inc_type: "distribut"
      }).then(function(res) {
        that.form = res.distribut;
      });
    },
    onSubmit() {
      var that = this;
      that.subLoading = true;
      updateConfigs("distribut", that.form).then(function(res) {
        that.subLoading = false;
        if (res.status == 1) {
          that.$message({
            message: "保存成功",
            type: "success"
          });
        } else {
          that.$message({
            showClose: true,
            message: "保存失败,失败原因:" + res.msg,
            type: "error"
          });
        }
      });
    },
    handleQRBack(res) {
      this.form.qr_back = res.result;
    },
    handleQRBigBack(res) {
      this.form.qr_big_back = res.result;
    },
    beforeAvatarUpload(file) {
      const isJPG =
        file.type === "image/gif" ||
        file.type === "image/jpg" ||
        file.type === "image/jpeg" ||
        file.type === "image/png";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error("上传图片只能是 JPG、JPEG、PNG、GIF 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传图片大小不能超过 2MB!");
      }
      return isJPG && isLt2M;
    }
  }
};
</script>
<style scoped>
>>> .el-input--mini .el-input__inner {
  width: 200px;
}
>>> .el-select--mini .el-input__inner {
  width: 100px;
}
>>> .avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
</style>
